<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Rubik Ultimate Framework
 * @version 	: 1.1
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 *
 * Created on	:  Jul 14, 2010
 *
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
RCoreImporter::cls( "mvc.AbstractController" );
//SysApplication::importModelCls('ProductFrontModel');


class AuctionFrontController extends AbstractController {
	
	var $_model;
	function __construct() {
		parent::__construct();
		SysApplication::importModelCls('AuctionModel');
		$this->_model = new AuctionModel();
	}
	
	function display() {
/*//		$config = SystemSite::getSiteConfig();
//		$email = $config->mailfrom;
//		RubikHelper::debugPrePrint($config->mailfrom);
		$sqlQuery = 'SELECT * FROM emailadmin'; 
		$rs = SysDatabase::loadObject( $sqlQuery);
		$email = $rs->email_admin;
		$ext_folder = SYS_ROOT_URL."ext";

		eval ( 'echo "' . SysApplication::loadTemplate ( "front/contactus" ) . '";' );*/
		
		echo 'cccccccccccc';
	}
	
	function edit(){
		eval ( 'echo "' . SysApplication::loadTemplate ( "front/edit" ) . '";' );
	}

	function upload(){
		$link_app = SystemSite::urlRoute('?app=auction&act=getModelGroup');
		$vehicleTypes = $this->_getVehicleTypes();
		$year = $this->_getYear();
		$make = $this->_getMaker();
		$damage = $this->_getDamage();
		$saleTitle = $this->_getSaleTitleType();
		$drive = $this->_getDriveType();
		$fuel = $this->_getFuelType();
		$state = $this->_getState();
		RExtImporter::cls('jscalendar.JsCalendarDateHtmlFieldInfo');
		$jsCtrl = new JsCalendarDateHtmlFieldInfo('saledate');
		$year = date('Y') - 18;
		$jsCtrl->setValue("{$year}-01-01");
//		$jsCtrl->setValue($modelDto);
		$saledateHtml = $jsCtrl->getHtmlInputData();
		$jsCtrl2 = new JsCalendarDateHtmlFieldInfo('endeddate');
		$jsCtrl2->setValue("{$year}-01-01");
//		$jsCtrl2->setValue($modelDto);
		$endeddateHtml = $jsCtrl2->getHtmlInputData();
		
		eval ( 'echo "' . SysApplication::loadTemplate ( "front/upload" ) . '";' );
	}
	
	
	
	//=====================================================================
	function _getVehicleTypes(){
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getVehicleTypes();
		foreach ($rs as $type){
			$result .= '<option value="'.$type->category_id.'">'.$type->name.'</option>';
		}
		return $result;
	}
	
	function _getYear(){
		$result = '';
		for ($i = 1980; $i < 2000; $i++){
			$result .= '<option value="'.$i.'">'.$i.'</option>';
		}
		$result .= '<option value="2000" selected="selected">2000</option>';
		for ($i = 2001; $i <= 2030; $i++){
			$result .= '<option value="'.$i.'">'.$i.'</option>';
		}
		return $result;
	}
	
	function _getMaker(){
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getMaker();
		$other = '';
		foreach ($rs as $maker){
			$name = $maker->name;
			if (strtoupper($name) != 'OTHER'){
				$result .= '<option value="'.$maker->maker_id.'">'.$name.'</option>';
			} else {
				$other = '<option value="'.$maker->maker_id.'">'.$name.'</option>';
			}
		}
		$result .= $other;
		return $result;
	}
	
	function _getDamage(){
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getDamage();
		foreach ($rs as $damage){
			$result .= '<option value="'.$damage->damage_id.'">'.$damage->damage.'</option>';
		}
		return $result;
	}
	
	function _getSaleTitleType(){
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getSaleTitleType();
		foreach ($rs as $sale){
			$result .= '<option value="'.$sale->saletitletype_id.'">'.$sale->saletitletype.'</option>';
		}
		return $result;
	}

	function _getDriveType(){
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getDriveType();
		foreach ($rs as $drive){
			$result .= '<option value="'.$drive->drive_id.'">'.$drive->drive.'</option>';
		}
		return $result;
	}

	function _getFuelType(){
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getFuelType();
		foreach ($rs as $fuel){
			$result .= '<option value="'.$fuel->fuel_id.'">'.$fuel->fuel.'</option>';
		}
		return $result;
	}
		
	function getModelGroup(){
		$id = SysRequest::getString("makeid");
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getModel($id);
		foreach ($rs as $model){
			$result .= '<option value="'.$model->model_id.'">'.$model->model_group.'</option>';
		}
		echo $result;
	}
		
	function _getState(){
		$result = '';
		$myModel = $this->_model;
		$rs = $myModel->getState();
		foreach ($rs as $state){
			$result .= '<option value="'.$state->state_id.'">'.$state->name.'</option>';
		}
		return $result;
	}
	
}
